package com.yexiong.server.dao.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.common.entity.CheckDetail;
import com.yexiong.dao.ICheckDetailDao;
import com.yexiong.dao.impl.CheckDetailDaoImpl;
import com.yexiong.server.dao.ICheckDetailServer;

public class CheckDetailServerImpl implements ICheckDetailServer{
	private ICheckDetailDao ICheckDetailDao=new CheckDetailDaoImpl();
	@Override
	public int delete(String date,int check_id) {
		return ICheckDetailDao.delete(date,check_id);
	}
	@Override
	public int update(CheckDetail checkDetail) {
		return ICheckDetailDao.update(checkDetail);
	}
	@Override
	public int getId(int id, String date) {
		return ICheckDetailDao.getId(id, date);
	}
	@Override
	public List<CheckDetail> selectTime(int checkId) {
		return ICheckDetailDao.selectTime(checkId);
	}
	@Override
	public boolean isTrueTime(int startTime, int endTime,int checkId) {
		List<CheckDetail> list=selectTime(checkId);
		boolean flag=true;
		for (int i = 0; i < list.size(); i++) {
			CheckDetail checkDetail=list.get(0);
			String startDate=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(checkDetail.getCheckDetailStartTime());
			String endDate=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(checkDetail.getCheckDetailEndTime());
			startDate=(startDate.split(" "))[1].replace(":", "");
			endDate=(endDate.split(" "))[1].replace(":", "");
			int start=Integer.parseInt(startDate);
			int end=Integer.parseInt(endDate);
			if ((startTime>=endTime)||(startTime>=start&&endTime<=end)||(startTime<=start&&endTime<=end&&endTime>=start)||
					(startTime>=start&&startTime<=end&&endTime>=end)||(startTime<=start&&endTime>=end)) {
				flag=false;
			}
			
		}
		
		return flag;
	}
	@Override
	public int insert(CheckDetail checkDetail) {
		return ICheckDetailDao.insert(checkDetail);
	}
	@Override
	public Date getFirstStartDate(int checkId) {
		return ICheckDetailDao.getFirstStartDate(checkId);
	}
	@Override
	public Date getLastEndDate(int checkId) {
		return ICheckDetailDao.getLastEndDate(checkId);
	}

}
